package modelLayer;


/**.
 * Forest class
 * @author Thomas Bonderup
 * @version 1.0.0
 */
public class Forest
{
    // instance variables
    private static int staticNr = 0;
	private int forestNr;
	private String name;
    private String location;
    private double squareKiloMetre;
    private String natureOfTrees;
    private double price;
	private Owner forestOwner;
	//private Tree treeType;
	private Tree treeType;

    /**
     * Constructor for objects of class Forest
     */
    public Forest(String name, String location, double squareKiloMetre, String natureOfTrees, double price, Owner forestOwner, Tree treeType)
    {
        staticNr++;
        forestNr = staticNr;
    	this.name = name;
        this.location = location;
        this.squareKiloMetre = squareKiloMetre;
        this.natureOfTrees = natureOfTrees;
        this.price = price; //price of the land pr square meter
		this.forestOwner = forestOwner;
		this.treeType = treeType;
    }


    public Tree getTreeType() {
    	return treeType;
    }
    
    public void setTreeType(Tree treeType) {
    	this.treeType = treeType;
    }
    
    public Owner getForestOwner() {
		return forestOwner;
	}



	public void setForestOwner(Owner forestOwner) {
		this.forestOwner = forestOwner;
	}



	/**
     * Methods of the class
     */

	public void setOwner(Owner owner){
		forestOwner = owner;
	}

	public void setTree(Tree treeType){
		this.treeType = treeType;
	}

    public String getName(){
        return name;
    }
    
    public void setName(String newName){
        name = newName;
    }
    
    public String getLocation(){
        return location;
    }
    
    public void setLocation(String newLocation){
        location = newLocation;
    }
    
    public double getSquareKiloMetre(){
        return squareKiloMetre;
    }
    
    public void setSquareMetre(double newSquareKiloMetre){
		if (newSquareKiloMetre >= 0)
		{
	        squareKiloMetre = newSquareKiloMetre;
	    }
    }
    
    public String getNatureOfTrees(){
        return natureOfTrees;
    }
    
    public void setNatureOfTrees(String newNatureOfTrees){
        natureOfTrees = newNatureOfTrees;
    }
    
    public double getPrice(){
        return price;
    }
    
    public void setPrice(double newPrice){
        if (newPrice>=0)
        {
            price = newPrice;
        }
    }

	public double getTotalCost(){
		double cost = -1;//if there is no trees associated -1 is returned
		if (treeType != null)
		{
			cost = (price*squareKiloMetre); //first calculate the price of the forest 
			cost += treeType.getCostPrSquareKilometre()*(squareKiloMetre); //then add the cost of the trees
			
		}
		return cost;
	}

	public double getTotalRevenue(){
		double revenue = -2;//if there is no trees associated -1 is returned
		if(treeType != null)
		{
			revenue = treeType.getRevenuePrSquareKilometre()*(squareKiloMetre);
			
		}
		return revenue;
	}

	public double getTotalProfit(){
		//will return -1 if there is no trees associated
		return getTotalRevenue()-getTotalCost();
	}

    public void printInformation(){
        System.out.println("#This forest is called: "+name);
        System.out.println("#And located at: "+location);
        System.out.println("#it covers an area of: "+squareKiloMetre+" squarekilometres");
        System.out.println("#The forest contains the following trees: "+natureOfTrees);
        System.out.println("#And the price per squaremetre is: "+price);
		//print the owner information but only if he is associated
		if(forestOwner != null)
		{
			forestOwner.printInformation();
		}
		//print tree informationo if its associated
		if(treeType != null)
		{
			treeType.printInformation();
		}
    }

	public int getForestNr() {
		return forestNr;
	}

	public void setForestNr(int forestNr) {
		this.forestNr = forestNr;
	}
}
